﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace GameStateManagement
{
    public class Ship : DrawableObject//Microsoft.Xna.Framework.DrawableGameComponent
    {
       // public Matrix worldTransformMatrix;
      //  protected float fScale;
      //  protected Vector3 vWorldPosition;
       // protected Quaternion qRotation;
       // protected bool hasChanged;

        //protected Model actorModel;
       // protected ContentManager contentManager;
        //protected Matrix[] actorBones;
        protected Utils.Timer timers;
       // protected Game game;

        //public BoundingSphere ModelBounds;
       // public BoundingSphere WorldBounds;

        public List<Missile> activeMissile;

        //Constant that determines how fast the ship can roll in forceBased mode
        protected float fRoll;
        //Constant that determines the speed of the ship
        protected float fSpeed;
        //Constant that determines how far away from the center the ship is created
        protected float fRadius;

        //Constant that determines the force of the thrusters in forceBased mode
        //protected float fThrust;
        
        //Variables used to calculate movement in forceBased mode
        //protected float fLeftForce, fUpForce, fRotForce;
        //protected float fUpAcc, fLeftAcc, fRotAcc;
        //protected float fUpVel, fLeftVel, fRotVel;
        //protected float fMass;

        protected float fFireRate, fLastFireTimeLeft, fLastFireTimeRight;


        //protected bool followCam;

        //Default false, can call switchMovement() to toggle
        //public bool forceBased;

        public Ship(Game game)
            : base(game)
        {
            this.game = (GameStateManagementGame)game;
            timers = new Utils.Timer();
            worldTransformMatrix = Matrix.Identity;
            activeMissile = new List<Missile>();

            fRadius = 550.0f;
            fScale = 1.0f;
            vWorldPosition = new Vector3(0.0f, 0.0f, fRadius);
            qRotation = Quaternion.Identity;
            hasChanged = false;

            fRoll = 0.03f;
            fSpeed = 370.0f;

            /*
            fThrust = 100.0f;
            fLeftForce = 0.0f;
            fUpForce = 0.0f;
            fRotForce = 0.0f;         
            fUpAcc = 0.0f;
            fLeftAcc = 0.0f;
            fRotAcc = 0.0f;
            fUpVel = 0.0f;
            fLeftVel = 0.0f;
            fRotVel = 0.0f;
            fMass = 30.0f;
            */

            fFireRate = 150.0f;
            fLastFireTimeLeft = 0.0f;
            fLastFireTimeRight = 0.0f;

            followCam = true;
            //forceBased = false;

        }

        public Vector3 enginePosition()
        {
            return this.Position + (this.worldTransformMatrix.Backward * 10.0f);
        }

        //Toggles Cam between fixed and ChaseCamera
        public void switchCam()
        {
            followCam = !followCam;
            foreach (Missile missile in activeMissile)
            {
                if (missile.followCam != this.followCam)
                {
                    missile.followCam = this.followCam;
                }
            }
        }

        //Toggles between forceBased and constant
        public void switchMove()
        {
            //forceBased = !forceBased;
            
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public float Scale
        {
            get{return fScale;}
            set
            {
                fScale = value;
                hasChanged = true;
            }
        }

        public Vector3 Position
        {
            get{return vWorldPosition;}
            set
            {
                vWorldPosition = value;
                hasChanged = true;
            }
        }


        public Quaternion Rotation
        {
            get{return qRotation;}
            set{qRotation = value;}
        }


       /* public void updateWorldTransformMatrix()
        {
            hasChanged = false;

            Matrix scaleMatrix = Matrix.CreateScale(fScale);
            Matrix rotationMatrix = Matrix.CreateFromQuaternion(qRotation);
            Matrix translationMatrix = Matrix.CreateTranslation(vWorldPosition);

            worldTransformMatrix = scaleMatrix;
            worldTransformMatrix *= rotationMatrix;
            worldTransformMatrix *= translationMatrix;

            WorldBounds.Center = vWorldPosition;
            WorldBounds.Radius = ModelBounds.Radius * fScale;
        }*/

        public override void Update(GameTime gameTime)
        {
            List<Missile> inactiveMissile = new List<Missile>();
            for (int i = 0; i < activeMissile.Count(); i++)
            {
                Missile missile = activeMissile[i];
                if (missile.Position.Length() > fRadius * 1.5f)
                {
                    game.Components.Remove(missile);
                    inactiveMissile.Add(missile);
                }
            }
            foreach (Missile missile in inactiveMissile)
            {
                activeMissile.Remove(missile);
            }
      
            /*
            if (forceBased)
            {
                float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

                fUpAcc = fUpForce / fMass;
                fLeftAcc = fLeftForce / fMass;
                fRotAcc = (fRotForce * 0.01f) / fMass;

                fUpVel = fUpVel + fUpAcc * dTime;
                fLeftVel = fLeftVel + fLeftAcc * dTime;
                fRotVel = fRotVel + fRotAcc * dTime;

                Vector3 left = this.worldTransformMatrix.Left;
                Vector3 newPos = this.Position + (this.worldTransformMatrix.Up * fUpVel);
                newPos.Normalize();
                newPos *= fRadius;
                this.Position = newPos;

                float fyAngle = (float)Math.Acos(this.Position.Y / fRadius);
                float fzAngle = (float)Math.Asin(this.Position.X / Math.Sqrt(Math.Pow(this.Position.X, 2) + Math.Pow(this.Position.Z, 2)));
                if (this.Position.Z < 0)
                {
                    fzAngle = (float)Math.PI - fzAngle;
                }

                Quaternion siderot = Quaternion.CreateFromAxisAngle(Vector3.UnitY, fzAngle);
                Quaternion uprot = Quaternion.CreateFromAxisAngle(-Vector3.UnitX, (float)(Math.PI / 2.0) - fyAngle);

                this.Rotation = siderot * uprot;

                updateWorldTransformMatrix();
                this.worldTransformMatrix.Left = left;
                this.worldTransformMatrix.Up = Vector3.Cross(this.worldTransformMatrix.Forward, this.worldTransformMatrix.Left);


                Vector3 up = this.worldTransformMatrix.Up;
                newPos = this.Position + (this.worldTransformMatrix.Left * fLeftVel);
                newPos.Normalize();
                newPos *= fRadius;
                this.Position = newPos;

                fyAngle = (float)Math.Acos(this.Position.Y / fRadius);
                fzAngle = (float)Math.Asin(this.Position.X / Math.Sqrt(Math.Pow(this.Position.X, 2) + Math.Pow(this.Position.Z, 2)));
                if (this.Position.Z < 0)
                {
                    fzAngle = (float)Math.PI - fzAngle;
                }

                siderot = Quaternion.CreateFromAxisAngle(Vector3.UnitY, fzAngle);
                uprot = Quaternion.CreateFromAxisAngle(-Vector3.UnitX, (float)(Math.PI / 2.0) - fyAngle);

                this.Rotation = siderot * uprot;

                updateWorldTransformMatrix();
                this.worldTransformMatrix.Up = up;
                this.worldTransformMatrix.Left = -Vector3.Cross(this.worldTransformMatrix.Forward, this.worldTransformMatrix.Up);

                Matrix roll = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(this.worldTransformMatrix.Forward, fRotVel));
                this.worldTransformMatrix *= roll;

            }*/

            timers.Update(gameTime);
            base.Update(gameTime);
        }

        public void verticalThrustOff()
        {
            //fUpForce = 0.0f;
        }
        public void horizontalThrustOff()
        {
            //fLeftForce = 0.0f;
        }
        public void rotationalThrustOff()
        {
            //fRotForce = 0.0f;
        }


        public void up(GameTime gameTime, Vector2 stick)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);


            //if (!forceBased)
            //{
                Vector3 left = this.worldTransformMatrix.Left;
                Vector3 newPos = this.Position + (this.worldTransformMatrix.Up * fSpeed * dTime * stick.Y);
                newPos.Normalize();
                newPos *= fRadius;
                this.Position = newPos;

                float fyAngle = (float)Math.Acos(this.Position.Y / fRadius);
                float fzAngle = (float)Math.Asin(this.Position.X / Math.Sqrt(Math.Pow(this.Position.X, 2) + Math.Pow(this.Position.Z, 2)));
                if (this.Position.Z < 0)
                {
                    fzAngle = (float)Math.PI - fzAngle;
                }


                Quaternion siderot = Quaternion.CreateFromAxisAngle(Vector3.UnitY, fzAngle);
                Quaternion uprot = Quaternion.CreateFromAxisAngle(-Vector3.UnitX, (float)(Math.PI / 2.0) - fyAngle);

                this.Rotation = siderot * uprot;

                updateWorldTransformMatrix();
                this.worldTransformMatrix.Left = left;
                this.worldTransformMatrix.Up = Vector3.Cross(this.worldTransformMatrix.Forward, this.worldTransformMatrix.Left);
            //}
            //else
            //{
            //    fUpForce = fThrust;
            //}
        }

        public void up(GameTime gameTime)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            Vector3 left = this.worldTransformMatrix.Left;
            Vector3 newPos = this.Position + (this.worldTransformMatrix.Up * fSpeed * dTime);
            newPos.Normalize();
            newPos *= fRadius;
            this.Position = newPos;

            float fyAngle = (float)Math.Acos(this.Position.Y / fRadius);
            float fzAngle = (float)Math.Asin(this.Position.X / Math.Sqrt(Math.Pow(this.Position.X, 2) + Math.Pow(this.Position.Z, 2)));
            if (this.Position.Z < 0)
            {
                fzAngle = (float)Math.PI - fzAngle;
            }


            Quaternion siderot = Quaternion.CreateFromAxisAngle(Vector3.UnitY, fzAngle);
            Quaternion uprot = Quaternion.CreateFromAxisAngle(-Vector3.UnitX, (float)(Math.PI / 2.0) - fyAngle);

            this.Rotation = siderot * uprot;

            updateWorldTransformMatrix();
            this.worldTransformMatrix.Left = left;
            this.worldTransformMatrix.Up = Vector3.Cross(this.worldTransformMatrix.Forward, this.worldTransformMatrix.Left);
        }

        public void down(GameTime gameTime, Vector2 stick)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            //if (!forceBased)
            //{
                Vector3 left = this.worldTransformMatrix.Left;
                Vector3 newPos = this.Position - (this.worldTransformMatrix.Up * fSpeed * dTime * -stick.Y);
                newPos.Normalize();
                newPos *= fRadius;
                this.Position = newPos;

                float fyAngle = (float)Math.Acos(this.Position.Y / fRadius);
                float fzAngle = (float)Math.Asin(this.Position.X / Math.Sqrt(Math.Pow(this.Position.X, 2) + Math.Pow(this.Position.Z, 2)));
                if (this.Position.Z < 0)
                {
                    fzAngle = (float)Math.PI - fzAngle;
                }

                Quaternion siderot = Quaternion.CreateFromAxisAngle(Vector3.UnitY, fzAngle);
                Quaternion uprot = Quaternion.CreateFromAxisAngle(-Vector3.UnitX, (float)(Math.PI / 2.0) - fyAngle);

                this.Rotation = siderot * uprot;

                updateWorldTransformMatrix();
                this.worldTransformMatrix.Left = left;
                this.worldTransformMatrix.Up = Vector3.Cross(this.worldTransformMatrix.Forward, this.worldTransformMatrix.Left);
            //}
            //else
            //{
            //    fUpForce = -fThrust;
            //}
        }

        public void down(GameTime gameTime)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            Vector3 left = this.worldTransformMatrix.Left;
            Vector3 newPos = this.Position - (this.worldTransformMatrix.Up * fSpeed * dTime);
            newPos.Normalize();
            newPos *= fRadius;
            this.Position = newPos;

            float fyAngle = (float)Math.Acos(this.Position.Y / fRadius);
            float fzAngle = (float)Math.Asin(this.Position.X / Math.Sqrt(Math.Pow(this.Position.X, 2) + Math.Pow(this.Position.Z, 2)));
            if (this.Position.Z < 0)
            {
                fzAngle = (float)Math.PI - fzAngle;
            }

            Quaternion siderot = Quaternion.CreateFromAxisAngle(Vector3.UnitY, fzAngle);
            Quaternion uprot = Quaternion.CreateFromAxisAngle(-Vector3.UnitX, (float)(Math.PI / 2.0) - fyAngle);

            this.Rotation = siderot * uprot;

            updateWorldTransformMatrix();
            this.worldTransformMatrix.Left = left;
            this.worldTransformMatrix.Up = Vector3.Cross(this.worldTransformMatrix.Forward, this.worldTransformMatrix.Left);
        }

        public void left(GameTime gameTime, Vector2 stick)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            //if (!forceBased)
            //{
                Vector3 up = this.worldTransformMatrix.Up;
                Vector3 newPos = this.Position + (this.worldTransformMatrix.Left * fSpeed * dTime * -stick.X);
                newPos.Normalize();
                newPos *= fRadius;
                this.Position = newPos;

                float fyAngle = (float)Math.Acos(this.Position.Y / fRadius);
                float fzAngle = (float)Math.Asin(this.Position.X / Math.Sqrt(Math.Pow(this.Position.X, 2) + Math.Pow(this.Position.Z, 2)));
                if (this.Position.Z < 0)
                {
                    fzAngle = (float)Math.PI - fzAngle;
                }

                Quaternion siderot = Quaternion.CreateFromAxisAngle(Vector3.UnitY, fzAngle);
                Quaternion uprot = Quaternion.CreateFromAxisAngle(-Vector3.UnitX, (float)(Math.PI / 2.0) - fyAngle);

                this.Rotation = siderot * uprot;

                updateWorldTransformMatrix();
                this.worldTransformMatrix.Up = up;
                this.worldTransformMatrix.Left = -Vector3.Cross(this.worldTransformMatrix.Forward, this.worldTransformMatrix.Up);
            //}
            //else
            //{
            //    fLeftForce = fThrust;
            //}
        }

        public void left(GameTime gameTime)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            Vector3 up = this.worldTransformMatrix.Up;
            Vector3 newPos = this.Position + (this.worldTransformMatrix.Left * fSpeed * dTime);
            newPos.Normalize();
            newPos *= fRadius;
            this.Position = newPos;

            float fyAngle = (float)Math.Acos(this.Position.Y / fRadius);
            float fzAngle = (float)Math.Asin(this.Position.X / Math.Sqrt(Math.Pow(this.Position.X, 2) + Math.Pow(this.Position.Z, 2)));
            if (this.Position.Z < 0)
            {
                fzAngle = (float)Math.PI - fzAngle;
            }

            Quaternion siderot = Quaternion.CreateFromAxisAngle(Vector3.UnitY, fzAngle);
            Quaternion uprot = Quaternion.CreateFromAxisAngle(-Vector3.UnitX, (float)(Math.PI / 2.0) - fyAngle);

            this.Rotation = siderot * uprot;

            updateWorldTransformMatrix();
            this.worldTransformMatrix.Up = up;
            this.worldTransformMatrix.Left = -Vector3.Cross(this.worldTransformMatrix.Forward, this.worldTransformMatrix.Up);
        }

        public void right(GameTime gameTime, Vector2 stick)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            //if (!forceBased)
            //{
                Vector3 up = this.worldTransformMatrix.Up;
                Vector3 newPos = this.Position - (this.worldTransformMatrix.Left * fSpeed * dTime * stick.X);
                newPos.Normalize();
                newPos *= fRadius;
                this.Position = newPos;

                float fyAngle = (float)Math.Acos(this.Position.Y / fRadius);
                float fzAngle = (float)Math.Asin(this.Position.X / Math.Sqrt(Math.Pow(this.Position.X, 2) + Math.Pow(this.Position.Z, 2)));
                if (this.Position.Z < 0)
                {
                    fzAngle = (float)Math.PI - fzAngle;
                }

                Quaternion siderot = Quaternion.CreateFromAxisAngle(Vector3.UnitY, fzAngle);
                Quaternion uprot = Quaternion.CreateFromAxisAngle(-Vector3.UnitX, (float)(Math.PI / 2.0) - fyAngle);

                this.Rotation = siderot * uprot;

                updateWorldTransformMatrix();
                this.worldTransformMatrix.Up = up;
                this.worldTransformMatrix.Left = -Vector3.Cross(this.worldTransformMatrix.Forward, this.worldTransformMatrix.Up);
            //}
            //else
            //{
            //    fLeftForce = -fThrust;
            //}
        }

        public void right(GameTime gameTime)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            Vector3 up = this.worldTransformMatrix.Up;
            Vector3 newPos = this.Position - (this.worldTransformMatrix.Left * fSpeed * dTime);
            newPos.Normalize();
            newPos *= fRadius;
            this.Position = newPos;

            float fyAngle = (float)Math.Acos(this.Position.Y / fRadius);
            float fzAngle = (float)Math.Asin(this.Position.X / Math.Sqrt(Math.Pow(this.Position.X, 2) + Math.Pow(this.Position.Z, 2)));
            if (this.Position.Z < 0)
            {
                fzAngle = (float)Math.PI - fzAngle;
            }

            Quaternion siderot = Quaternion.CreateFromAxisAngle(Vector3.UnitY, fzAngle);
            Quaternion uprot = Quaternion.CreateFromAxisAngle(-Vector3.UnitX, (float)(Math.PI / 2.0) - fyAngle);

            this.Rotation = siderot * uprot;

            updateWorldTransformMatrix();
            this.worldTransformMatrix.Up = up;
            this.worldTransformMatrix.Left = -Vector3.Cross(this.worldTransformMatrix.Forward, this.worldTransformMatrix.Up);
        }

        public void cwrot(GameTime gameTime, Vector2 stick)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            //if (!forceBased)
            //{
                Matrix roll = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(this.worldTransformMatrix.Forward, fRoll * stick.X));
                this.worldTransformMatrix *= roll;
            //}
            //else
            //{
            //    fRotForce = fThrust;
            //}
        }

        public void cwrot(GameTime gameTime)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            Matrix roll = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(this.worldTransformMatrix.Forward, fRoll));
            this.worldTransformMatrix *= roll;
        }

        public void ccwrot(GameTime gameTime, Vector2 stick)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            //if (!forceBased)
            //{
                Matrix roll = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(this.worldTransformMatrix.Forward, -fRoll * -stick.X));
                this.worldTransformMatrix *= roll;
            //}
            //else
            //{
            //    fRotForce = -fThrust;
            //}
        }
        public void ccwrot(GameTime gameTime)
        {
            float dTime = ((float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f);

            Matrix roll = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(this.worldTransformMatrix.Forward, -fRoll));
            this.worldTransformMatrix *= roll;
        }

        public void fireLeft(GameTime gameTime, float radius)
        {
            float currentTime = (float)gameTime.TotalGameTime.TotalMilliseconds;
            if (currentTime - fLastFireTimeLeft > fFireRate)
            {
                Vector3 newConverge = Vector3.Zero - this.worldTransformMatrix.Backward * (radius/1.25f);

                Missile missile = new Missile(game);
                game.Components.Add(missile);
                this.activeMissile.Add(missile);

                missile.Initialize();
                missile.Position = this.Position + (this.worldTransformMatrix.Left * 22.0f) + (this.worldTransformMatrix.Up * 7.0f) + (this.worldTransformMatrix.Forward * 7.0f);
                missile.updateRotation(newConverge);


                missile.Rotation = missile.Rotation * Quaternion.CreateFromAxisAngle(Vector3.UnitY, (float)Math.PI);

                Vector3 force = missile.worldTransformMatrix.Forward;
                missile.Velocity = force * 400.0f;
                missile.Force = force * 400.0f;


                if (missile.followCam != this.followCam)
                {
                    missile.followCam = this.followCam;
                }

                fLastFireTimeLeft = currentTime;
            }
            

        }

        public void fireRight(GameTime gameTime, float radius)
        {
            

            float currentTime = (float)gameTime.TotalGameTime.TotalMilliseconds;
            if (currentTime - fLastFireTimeRight > fFireRate)
            {

                Vector3 newConverge = Vector3.Zero - (this.worldTransformMatrix.Backward * (radius/1.25f));

                Missile missile = new Missile(game);
                game.Components.Add(missile);
                this.activeMissile.Add(missile);

                missile.Initialize();
                missile.Position = this.Position + (this.worldTransformMatrix.Right * 22.0f) + (this.worldTransformMatrix.Up * 7.0f) + (this.worldTransformMatrix.Forward * 7.0f);
                missile.updateRotation(newConverge);

                missile.Rotation = missile.Rotation * Quaternion.CreateFromAxisAngle(Vector3.UnitY, (float)Math.PI);

                Vector3 force = missile.worldTransformMatrix.Forward;
                missile.Velocity = force * 400.0f;
                missile.Force = force * 400.0f;


                if (missile.followCam != this.followCam)
                {
                    missile.followCam = this.followCam;
                }

                fLastFireTimeRight = currentTime;
            }


        }

        protected override void LoadContent()
        {
            contentManager = new ContentManager(Game.Services, "Content");
            actorModel = contentManager.Load<Model>("da_ship");
            actorBones = new Matrix[actorModel.Bones.Count];
            celShader = contentManager.Load<Effect>("CelShader");
            texture = contentManager.Load<Texture2D>("plane_texture");
            celShader.Parameters["Texture"].SetValue(texture);
            celShader.Parameters["textureEnabled"].SetValue(true);
            changeEffectUsedByModel(actorModel, celShader);


            base.LoadContent();

            foreach (ModelMesh mesh in actorModel.Meshes)
            {
                ModelBounds = BoundingSphere.CreateMerged(ModelBounds,
                mesh.BoundingSphere);
            }
        }

        protected override void UnloadContent()
        {
            contentManager.Unload();
            base.UnloadContent();
        }

       /* public override void Draw(GameTime gameTime)
        {
            if (hasChanged)
            {
                updateWorldTransformMatrix();
            }

            GraphicsDevice.RenderState.DepthBufferEnable = true;
            actorModel.CopyAbsoluteBoneTransformsTo(actorBones);
            foreach (ModelMesh mesh in actorModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World =
                    actorBones[mesh.ParentBone.Index] * worldTransformMatrix;
                    if (followCam)
                    {
                        effect.View = GameplayScreen.camera.View;
                        effect.Projection = GameplayScreen.camera.Projection;
                    }
                    else
                    {
                        effect.View = GameplayScreen.CameraMatrix;
                        effect.Projection = GameplayScreen.ProjectionMatrix;
                    }
                    effect.EnableDefaultLighting();
                    effect.PreferPerPixelLighting = true;
                    effect.AmbientLightColor = GameplayScreen.ambientLightColor;
                    effect.DirectionalLight0.DiffuseColor = GameplayScreen.diffuseColor;
                    effect.DirectionalLight0.Direction = GameplayScreen.diffuseDirection;
                    effect.SpecularColor = GameplayScreen.specularColor;
                    effect.SpecularPower = GameplayScreen.specularPower;

                }
                mesh.Draw();
            }
            base.Draw(gameTime);
        }*/
    }
}
